package gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * Created by kkmike999 on 2016/05/08.
 */
public class GsonHelper {

	/**
	 * 获取Gson对象。解析json时，会对number类特殊处理，例如 空字符串->0
	 *
	 * @return
	 */
	public static Gson getGson() {
		return new GsonBuilder().registerTypeAdapter(int.class, NumberTypeAdapters.INTEGER_TYPE_ADAPTER)
		                        .registerTypeAdapter(double.class, NumberTypeAdapters.DOUBLE_TYPE_ADATPER)
		                        .registerTypeAdapter(float.class, NumberTypeAdapters.FLOAT_TYPE_ADATPER)
		                        .registerTypeAdapter(long.class, NumberTypeAdapters.LONG_TYPE_ADAPTER)
		                        .registerTypeAdapter(Integer.class, NumberTypeAdapters.INTEGER_TYPE_ADAPTER)
		                        .registerTypeAdapter(Double.class, NumberTypeAdapters.DOUBLE_TYPE_ADATPER)
		                        .registerTypeAdapter(Float.class, NumberTypeAdapters.FLOAT_TYPE_ADATPER)
		                        .registerTypeAdapter(Long.class, NumberTypeAdapters.LONG_TYPE_ADAPTER)
		                        .create();
	}
}
